package com.steakliu.sun.configcenter.api;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

/**
 * 功能说明： 从注册中心获取得配置信息转换为实体
 * <p>
 * Original @Author: steakliu-刘牌, 2023-02-08  17:20
 * <p>
 * Copyright (C)2020-2022  steakliu All rights reserved.
 */
public class ConfigInfoTransfer {

    private static final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

    /**
     * yml转对象
     * @param content
     * @param clazz
     * @param <T>
     * @return
     */
    public static <T> T ymlTo(String content, Class<T> clazz){
        T t = null;
        try {
            t = (T) mapper.readValue(content, clazz);
        }catch (Exception e){
            e.printStackTrace();
        }
        return t;
    }
}
